using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using System.Collections.Generic;
using System.IO;

public partial class admin_ThongKeDoanhThu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
    }

    private void LoadData()
    {
        ReportDocument doc = new ReportDocument();
        DataTable result = (new OrderBO()).OrderGetAll();

        List<OrderEntity> list = new List<OrderEntity>();
        if(result.Rows.Count > 0)
        {
            foreach(DataRow row in result.Rows)
            {
                OrderEntity entity = new OrderEntity();
                long orderId;
                long.TryParse(row["OrderId"].ToString(), out orderId);
                entity.OrderId = orderId;
                long menuId;
                long.TryParse(row["MenuId"].ToString(), out menuId);
                entity.MenuId = menuId;
                long foodId;
                long.TryParse(row["FoodId"].ToString(), out foodId);
                entity.FoodId = foodId;
                decimal quantity;
                decimal.TryParse(row["Quantity"].ToString(),out quantity);
                entity.Quantity = quantity;
                entity.Name = row["Name"].ToString();
                entity.Address = row["Address"].ToString();
                short type;
                short.TryParse(row["PayType"].ToString(), out type);
                entity.PayType = type;
                entity.TotalAmount = decimal.Parse(row["TotalAmount"].ToString());
                list.Add(entity);
            }
        }
        //doc.Load("DoanhThuReport.rpt");
        LoadReport(doc, "DoanhThuReport.rpt");
        doc.SetDataSource(list);
        
        CrystalReportViewer1.ReportSource = doc;
        CrystalReportViewer1.DataBind();
    }

    /// <summary>
    /// Load Report
    /// </summary>
    /// <param name="rptDoc"></param>
    /// <param name="reportName"></param>
    private void LoadReport(ReportDocument rptDoc, string reportName)
    {
        string reportFolderPath = Server.MapPath(@"Reports\\");

        // Get Report file.      
        string reportFilePath = Path.Combine(reportFolderPath, reportName);

        rptDoc.Load(reportFilePath);
    }
}
